import { UploadFile } from "antd";
import { request } from "../request/request";
import { SoapOpera } from "../Types/SoapOpera";
import { ListRequestParams } from "../Types/Requset";

const perfix = "/soapOpera";
export const createSoapOpera = (SoapOpera: SoapOpera) => {
    return request({
        url: `${perfix}/create_soap_opera`,
        method: "post",
        data: SoapOpera,
    }) as Promise<BaseResponse<SoapOpera>>;
};

export const getSoapOperaList = (params: ListRequestParams<SoapOpera>) => {
    return request({
        url: `${perfix}/get_soap_opera_list`,
        method: "get",
        params,
    }) as Promise<ListResponse<SoapOpera>>;
};

export const deleteSoapOpera = (ids: number[]) => {
    return request({
        url: `${perfix}/delete_soap_opera`,
        method: "delete",
        data: { ids },
    }) as Promise<BaseResponse<SoapOpera>>;
};

export const updateSoapOpera = (SoapOpera: SoapOpera) => {
    return request({
        url: `${perfix}/update_soap_opera`,
        method: "put",
        data: SoapOpera,
    }) as Promise<BaseResponse<SoapOpera>>;
};

export const uploadSoapOperaCover = (file: UploadFile) => {
    const formData = new FormData();
    formData.append("file", file as unknown as File);
    return request({
        url: "/files/upload_soap_opera_cover",
        method: "put",
        data: formData,
    });
};
